package myLandscape.Main;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.view.View;

public class Drawer extends View  {
	public Drawer(Context context) {
            super(context);
           
            // TODO Auto-generated constructor stub
    }

    @Override
    protected void onDraw(Canvas canvas) {
            // TODO Auto-generated method stub
    	 	boolean photosTaken = false;
    	 	int numberOfPhotos = 0;
            
             //draw circle        
           	drawGreenCircle(canvas);
            
           	//Make button
           	
           	while(!(photosTaken)) {
           		
           		if (Main.anglesM.shouldDrawDownArrow()) {
           			drawDownArrow(canvas);
           		} else {
           			//erase
           		}
           		
           		if (Main.anglesM.shouldDrawUpArrow()) {
           			drawUpArrow(canvas);
           		} else {
           			//erase
           		}
           		
           		if (Main.anglesM.shouldDrawLeftArrow()) {
           			drawLeftArrow(canvas);
           		} else {
           			//erase
           		}

           		if (Main.anglesM.shouldDrawRightArrow()) {
           			drawRightArrow(canvas);
           		} else {
           			//erase
           		}
           		
           		if (Main.anglesM.isInTheRightPosition()) {
           			drawGreenCircle(canvas);
           			//wait 3 seconds, check position again, take photo
           			
           			numberOfPhotos++;
           			if (numberOfPhotos == 6) {
           				photosTaken = true;
           			}
           			//set new angle
           		} else {
           			drawRedCircle(canvas);
           		}
           		
           	}
                    
            //draw arrow
            //drawRightArrow(canvas);
            //drawLeftArrow(canvas);
            //drawDownArrow(canvas);
            //drawUpArrow(canvas);
			

            super.onDraw(canvas);
    }
    
    private void drawRedCircle(Canvas canvas) {
    	 Paint paint2 = new Paint();
         paint2.setStyle(Paint.Style.STROKE);
         paint2.setStrokeWidth(5);
         paint2.setColor(Color.RED);
         canvas.drawCircle(640, 400, 20, paint2);
    }
    
    private void drawGreenCircle(Canvas canvas) {
   	 Paint paint2 = new Paint();
     paint2.setStyle(Paint.Style.STROKE);
     paint2.setStrokeWidth(5);
     paint2.setColor(Color.GREEN);
     canvas.drawCircle(640, 400, 20, paint2);
}
    
    private void drawRightArrow(Canvas canvas) {
    	Paint paint = new Paint();
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(Color.WHITE);
        canvas.drawRect(680,390,720,410,paint); 
		Path path = new Path();
		path.moveTo(0, 40);
		path.lineTo(40, 20);
		path.lineTo(0, 0);
		path.close();
		path.offset(720, 380);
		canvas.drawPath(path, paint);
    }
    
    private void drawLeftArrow(Canvas canvas) {
    	Paint paint = new Paint();
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(Color.WHITE);
        canvas.drawRect(540,390,600,410,paint); 
		Path path = new Path();
		path.moveTo(0, -40);
		path.lineTo(-40, -20);
		path.lineTo(0, 0);
		path.close();
		path.offset(560, 420);
		canvas.drawPath(path, paint);
    }
    
    private void drawUpArrow(Canvas canvas) {
    	Paint paint = new Paint();
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(Color.WHITE);
        canvas.drawRect(630,320,650,360,paint); 
		Path path = new Path();
		path.moveTo(-40, 0);
		path.lineTo(-20, -40);
		path.lineTo(0, 0);
		path.close();
		path.offset(660, 320);
		canvas.drawPath(path, paint);
    }
    
    private void drawDownArrow(Canvas canvas) {
    	Paint paint = new Paint();
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(Color.WHITE);
        canvas.drawRect(630,440,650,480,paint); 
		Path path = new Path();
		path.moveTo(40, 0);
		path.lineTo(20, 40);
		path.lineTo(0, 0);
		path.close();
		path.offset(620, 480);
		canvas.drawPath(path, paint);
    }
    

} 